#include<bits/stdc++.h>
using namespace std;

struct edge{
	int x, y, c, pre;
}a[5050];

int n, m, d, alen, last[5050], st, ed, sh[110];
bool v[110], distroy[110][110];

void ins(int x, int y, int c) {
	a[++alen] = edge{x, y, c, last[x]};
	last[x] = alen;
}

void spfa() {
//	 spfa是用来求最短路的，但是在这个题目下我们的目的并非直接求最短路，而是求出最短的修复路径，因此未毁路径直接看作 0 
	memset(sh, 0x3f, sizeof(sh));
	memset(v, false, sizeof(v));
	queue<int> q;
	sh[st] = 0; q.push(st); v[st] = true;
	while(!q.empty()) {
		int x = q.front();
		for (int k = last[x]; k; k = a[k].pre) {
			int y = a[k].y;
			if (sh[y] > sh[x] + (distroy[x][y] ? a[k].c : 0)) {
				sh[y] = sh[x] + (distroy[x][y] ? a[k].c : 0);
				if (!v[y]) {
					q.push(y);
					v[y] = true;
				}
			}
		}
		q.pop();
		v[x] = false;
	}
	printf("%d\n", sh[ed]);
}

int main () {
	while(scanf("%d%d", &n, &m) != EOF) {
		alen = 0;
		memset(last, 0, sizeof(last));
		memset(distroy, false, sizeof(distroy));
		while(m--) {
			int x, y, c;
			scanf("%d%d%d", &x, &y, &c);
			ins(x, y, c);
			ins(y, x, c);
		}
		scanf("%d", &d);
		while(d--) {
			int x, y;
			scanf("%d%d", &x, &y);
			distroy[x][y] = distroy[y][x] = true;
		}
		scanf("%d%d", &st, &ed);
		spfa();
	}
	return 0;
}